package me.helllp.book.concurrent.ch05;

public class FutureData implements Data{
	protected RealData realData = null;
	protected boolean isReady = false;
	
	public synchronized void setRealData(RealData realdata){
		if(isReady){
			return;
		}
		
		this.realData = realdata;
		isReady = true;
		notifyAll();
	}
	
	@Override
	public synchronized String getResult() {
		while(!isReady){
			try {
				wait();
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
		
		return this.realData.getResult();
	}

}
